<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveRecord::Sanitization::ClassMethods</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActiveRecord::Sanitization::ClassMethods 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/activerecord/lib/active_record/sanitization_rb.html">activerecord/lib/active_record/sanitization.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ClassMethods.html#method-i-expand_hash_conditions_for_aggregates">expand_hash_conditions_for_aggregates</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ClassMethods.html#method-i-sanitize_conditions">sanitize_conditions</a>,
              </li>
            
              
              <li>
                <a href="ClassMethods.html#method-i-sanitize_sql">sanitize_sql</a>,
              </li>
            
              
              <li>
                <a href="ClassMethods.html#method-i-sanitize_sql_array">sanitize_sql_array</a>,
              </li>
            
              
              <li>
                <a href="ClassMethods.html#method-i-sanitize_sql_for_assignment">sanitize_sql_for_assignment</a>,
              </li>
            
              
              <li>
                <a href="ClassMethods.html#method-i-sanitize_sql_for_conditions">sanitize_sql_for_conditions</a>,
              </li>
            
              
              <li>
                <a href="ClassMethods.html#method-i-sanitize_sql_hash">sanitize_sql_hash</a>,
              </li>
            
              
              <li>
                <a href="ClassMethods.html#method-i-sanitize_sql_hash_for_assignment">sanitize_sql_hash_for_assignment</a>,
              </li>
            
              
              <li>
                <a href="ClassMethods.html#method-i-sanitize_sql_hash_for_conditions">sanitize_sql_hash_for_conditions</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Protected methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-expand_hash_conditions_for_aggregates">
            
              <b>expand_hash_conditions_for_aggregates</b>(attrs)
            
            <a href="ClassMethods.html#method-i-expand_hash_conditions_for_aggregates" name="method-i-expand_hash_conditions_for_aggregates" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Accepts a hash of SQL conditions and replaces those attributes that
correspond to a <code>composed_of</code> relationship with their expanded
aggregate attribute values. Given:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Person</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">composed_of</span> :<span class="ruby-identifier">address</span>, <span class="ruby-identifier">class_name</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;Address&quot;</span>,
    <span class="ruby-identifier">mapping</span><span class="ruby-operator">:</span> [<span class="ruby-node">%w(address_street street)</span>, <span class="ruby-node">%w(address_city city)</span>]
<span class="ruby-keyword">end</span>
</pre>

<p>Then:</p>

<pre class="ruby">{ <span class="ruby-identifier">address</span><span class="ruby-operator">:</span> <span class="ruby-constant">Address</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;813 abc st.&quot;</span>, <span class="ruby-string">&quot;chicago&quot;</span>) }
  <span class="ruby-comment"># =&gt; { address_street: &quot;813 abc st.&quot;, address_city: &quot;chicago&quot; }</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-expand_hash_conditions_for_aggregates_source')" id="l_method-i-expand_hash_conditions_for_aggregates_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/0a71c7b8644c554c8c97b8b682c7eccd92f6067b/activerecord/lib/active_record/sanitization.rb#L55" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-expand_hash_conditions_for_aggregates_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/sanitization.rb, line 55</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">expand_hash_conditions_for_aggregates</span>(<span class="ruby-identifier">attrs</span>)
  <span class="ruby-identifier">expanded_attrs</span> = {}
  <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">aggregation</span> = <span class="ruby-identifier">reflect_on_aggregation</span>(<span class="ruby-identifier">attr</span>.<span class="ruby-identifier">to_sym</span>)
      <span class="ruby-identifier">mapping</span> = <span class="ruby-identifier">aggregation</span>.<span class="ruby-identifier">mapping</span>
      <span class="ruby-identifier">mapping</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">field_attr</span>, <span class="ruby-identifier">aggregate_attr</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">mapping</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-number">1</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">value</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">aggregate_attr</span>)
          <span class="ruby-identifier">expanded_attrs</span>[<span class="ruby-identifier">field_attr</span>] = <span class="ruby-identifier">value</span>
        <span class="ruby-keyword">else</span>
          <span class="ruby-identifier">expanded_attrs</span>[<span class="ruby-identifier">field_attr</span>] = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">aggregate_attr</span>)
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">expanded_attrs</span>[<span class="ruby-identifier">attr</span>] = <span class="ruby-identifier">value</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">expanded_attrs</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-sanitize_conditions">
            
              <b>sanitize_conditions</b>(condition, table_name = self.table_name)
            
            <a href="ClassMethods.html#method-i-sanitize_conditions" name="method-i-sanitize_conditions" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-sanitize_sql">
            
              <b>sanitize_sql</b>(condition, table_name = self.table_name)
            
            <a href="ClassMethods.html#method-i-sanitize_sql" name="method-i-sanitize_sql" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="ClassMethods.html#method-i-sanitize_conditions">sanitize_conditions</a>
            </div>
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-sanitize_sql_array">
            
              <b>sanitize_sql_array</b>(ary)
            
            <a href="ClassMethods.html#method-i-sanitize_sql_array" name="method-i-sanitize_sql_array" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Accepts an array of conditions. The array has each value sanitized and
interpolated into the SQL statement.</p>

<pre>[&quot;name='%s' and group_id='%s'&quot;, &quot;foo'bar&quot;, 4]  returns  &quot;name='foo''bar' and group_id='4'&quot;</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-sanitize_sql_array_source')" id="l_method-i-sanitize_sql_array_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/0a71c7b8644c554c8c97b8b682c7eccd92f6067b/activerecord/lib/active_record/sanitization.rb#L110" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-sanitize_sql_array_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/sanitization.rb, line 110</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">sanitize_sql_array</span>(<span class="ruby-identifier">ary</span>)
  <span class="ruby-identifier">statement</span>, *<span class="ruby-identifier">values</span> = <span class="ruby-identifier">ary</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">statement</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/:\w+/</span>
    <span class="ruby-identifier">replace_named_bind_variables</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>)
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-string">'?'</span>)
    <span class="ruby-identifier">replace_bind_variables</span>(<span class="ruby-identifier">statement</span>, <span class="ruby-identifier">values</span>)
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">statement</span>.<span class="ruby-identifier">blank?</span>
    <span class="ruby-identifier">statement</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">statement</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">values</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">quote_string</span>(<span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>) }
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-sanitize_sql_for_assignment">
            
              <b>sanitize_sql_for_assignment</b>(assignments, default_table_name = self.table_name)
            
            <a href="ClassMethods.html#method-i-sanitize_sql_for_assignment" name="method-i-sanitize_sql_for_assignment" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Accepts an array, hash, or string of SQL conditions and sanitizes them into
a valid SQL fragment for a SET clause.</p>

<pre>{ name: nil, group_id: 4 }  returns &quot;name = NULL , group_id='4'&quot;</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-sanitize_sql_for_assignment_source')" id="l_method-i-sanitize_sql_for_assignment_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/0a71c7b8644c554c8c97b8b682c7eccd92f6067b/activerecord/lib/active_record/sanitization.rb#L36" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-sanitize_sql_for_assignment_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/sanitization.rb, line 36</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">sanitize_sql_for_assignment</span>(<span class="ruby-identifier">assignments</span>, <span class="ruby-identifier">default_table_name</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">table_name</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">assignments</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Array</span>; <span class="ruby-identifier">sanitize_sql_array</span>(<span class="ruby-identifier">assignments</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Hash</span>;  <span class="ruby-identifier">sanitize_sql_hash_for_assignment</span>(<span class="ruby-identifier">assignments</span>, <span class="ruby-identifier">default_table_name</span>)
  <span class="ruby-keyword">else</span>        <span class="ruby-identifier">assignments</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-sanitize_sql_for_conditions">
            
              <b>sanitize_sql_for_conditions</b>(condition, table_name = self.table_name)
            
            <a href="ClassMethods.html#method-i-sanitize_sql_for_conditions" name="method-i-sanitize_sql_for_conditions" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Accepts an array, hash, or string of SQL conditions and sanitizes them into
a valid SQL fragment for a WHERE clause.</p>

<pre>[&quot;name='%s' and group_id='%s'&quot;, &quot;foo'bar&quot;, 4]  returns  &quot;name='foo''bar' and group_id='4'&quot;
{ name: &quot;foo'bar&quot;, group_id: 4 }  returns &quot;name='foo''bar' and group_id='4'&quot;
&quot;name='foo''bar' and group_id='4'&quot; returns &quot;name='foo''bar' and group_id='4'&quot;</pre>
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="ClassMethods.html#method-i-sanitize_sql">sanitize_sql</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-sanitize_sql_for_conditions_source')" id="l_method-i-sanitize_sql_for_conditions_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/0a71c7b8644c554c8c97b8b682c7eccd92f6067b/activerecord/lib/active_record/sanitization.rb#L22" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-sanitize_sql_for_conditions_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/sanitization.rb, line 22</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">sanitize_sql_for_conditions</span>(<span class="ruby-identifier">condition</span>, <span class="ruby-identifier">table_name</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">table_name</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">condition</span>.<span class="ruby-identifier">blank?</span>

  <span class="ruby-keyword">case</span> <span class="ruby-identifier">condition</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Array</span>; <span class="ruby-identifier">sanitize_sql_array</span>(<span class="ruby-identifier">condition</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Hash</span>;  <span class="ruby-identifier">sanitize_sql_hash_for_conditions</span>(<span class="ruby-identifier">condition</span>, <span class="ruby-identifier">table_name</span>)
  <span class="ruby-keyword">else</span>        <span class="ruby-identifier">condition</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-sanitize_sql_hash">
            
              <b>sanitize_sql_hash</b>(attrs, default_table_name = self.table_name)
            
            <a href="ClassMethods.html#method-i-sanitize_sql_hash" name="method-i-sanitize_sql_hash" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-sanitize_sql_hash_for_assignment">
            
              <b>sanitize_sql_hash_for_assignment</b>(attrs, table)
            
            <a href="ClassMethods.html#method-i-sanitize_sql_hash_for_assignment" name="method-i-sanitize_sql_hash_for_assignment" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Sanitizes a hash of attribute/value pairs into SQL conditions for a SET
clause.</p>

<pre class="ruby">{ <span class="ruby-identifier">status</span><span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">group_id</span><span class="ruby-operator">:</span> <span class="ruby-value">1</span> }
  <span class="ruby-comment"># =&gt; &quot;status = NULL , group_id = 1&quot;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-sanitize_sql_hash_for_assignment_source')" id="l_method-i-sanitize_sql_hash_for_assignment_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/0a71c7b8644c554c8c97b8b682c7eccd92f6067b/activerecord/lib/active_record/sanitization.rb#L101" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-sanitize_sql_hash_for_assignment_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/sanitization.rb, line 101</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">sanitize_sql_hash_for_assignment</span>(<span class="ruby-identifier">attrs</span>, <span class="ruby-identifier">table</span>)
  <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
    <span class="ruby-node">&quot;#{connection.quote_table_name_for_assignment(table, attr)} = #{quote_bound_value(value)}&quot;</span>
  <span class="ruby-keyword">end</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">', '</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-sanitize_sql_hash_for_conditions">
            
              <b>sanitize_sql_hash_for_conditions</b>(attrs, default_table_name = self.table_name)
            
            <a href="ClassMethods.html#method-i-sanitize_sql_hash_for_conditions" name="method-i-sanitize_sql_hash_for_conditions" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Sanitizes a hash of attribute/value pairs into SQL conditions for a WHERE
clause.</p>

<pre class="ruby">{ <span class="ruby-identifier">name</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;foo'bar&quot;</span>, <span class="ruby-identifier">group_id</span><span class="ruby-operator">:</span> <span class="ruby-value">4</span> }
  <span class="ruby-comment"># =&gt; &quot;name='foo''bar' and group_id= 4&quot;</span>
{ <span class="ruby-identifier">status</span><span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">group_id</span><span class="ruby-operator">:</span> [<span class="ruby-value">1</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>] }
  <span class="ruby-comment"># =&gt; &quot;status IS NULL and group_id IN (1,2,3)&quot;</span>
{ <span class="ruby-identifier">age</span><span class="ruby-operator">:</span> <span class="ruby-value">13</span><span class="ruby-operator">..</span><span class="ruby-value">18</span> }
  <span class="ruby-comment"># =&gt; &quot;age BETWEEN 13 AND 18&quot;</span>
{ <span class="ruby-string">'other_records.id'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">7</span> }
  <span class="ruby-comment"># =&gt; &quot;`other_records`.`id` = 7&quot;</span>
{ <span class="ruby-identifier">other_records</span><span class="ruby-operator">:</span> { <span class="ruby-identifier">id</span><span class="ruby-operator">:</span> <span class="ruby-value">7</span> } }
  <span class="ruby-comment"># =&gt; &quot;`other_records`.`id` = 7&quot;</span>
</pre>

<p>And for value objects on a composed_of relationship:</p>

<pre class="ruby">{ <span class="ruby-identifier">address</span><span class="ruby-operator">:</span> <span class="ruby-constant">Address</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;123 abc st.&quot;</span>, <span class="ruby-string">&quot;chicago&quot;</span>) }
  <span class="ruby-comment"># =&gt; &quot;address_street='123 abc st.' and address_city='chicago'&quot;</span>
</pre>
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="ClassMethods.html#method-i-sanitize_sql_hash">sanitize_sql_hash</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-sanitize_sql_hash_for_conditions_source')" id="l_method-i-sanitize_sql_hash_for_conditions_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/0a71c7b8644c554c8c97b8b682c7eccd92f6067b/activerecord/lib/active_record/sanitization.rb#L88" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-sanitize_sql_hash_for_conditions_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/sanitization.rb, line 88</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">sanitize_sql_hash_for_conditions</span>(<span class="ruby-identifier">attrs</span>, <span class="ruby-identifier">default_table_name</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">table_name</span>)
  <span class="ruby-identifier">attrs</span> = <span class="ruby-identifier">expand_hash_conditions_for_aggregates</span>(<span class="ruby-identifier">attrs</span>)

  <span class="ruby-identifier">table</span> = <span class="ruby-constant">Arel</span><span class="ruby-operator">::</span><span class="ruby-constant">Table</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">arel_engine</span>).<span class="ruby-identifier">alias</span>(<span class="ruby-identifier">default_table_name</span>)
  <span class="ruby-constant">PredicateBuilder</span>.<span class="ruby-identifier">build_from_hash</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">attrs</span>, <span class="ruby-identifier">table</span>).<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">b</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">visitor</span>.<span class="ruby-identifier">accept</span> <span class="ruby-identifier">b</span>
  }.<span class="ruby-identifier">join</span>(<span class="ruby-string">' AND '</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    